#ifndef _KEY_PANEL_H
#define _KEY_PANEL_H

//Global Variables and functions defined in PANEL module
//ext uchar EjectKey_Timer;
typedef struct
{
	unsigned F_TEMP_ON          :1;
	unsigned F_SEND_776		    :1;
	unsigned F_WINCE_BTINIT		:1;	
	unsigned F_PRESET_FRQ    	:1;	
	unsigned F_iPod_Video       :1;
	unsigned F_NAVI_INSETUP		:1;
	unsigned F_Volume			:1;	
	unsigned F_ScreenSetup		:1;
	
}_KEY_FLAG0;
typedef union
{
	uchar	byte;
	_KEY_FLAG0 field;
}KEY_FLAG0;
ext     KEY_FLAG0 Key_Flag0;

#define Set_776_SENDING         Key_Flag0.field.F_SEND_776=1;
#define Clr_776_SENDING         Key_Flag0.field.F_SEND_776=0;
#define Get_776_SENDING         Key_Flag0.field.F_SEND_776

#define Set_PRESET_FRQ           Key_Flag0.field.F_PRESET_FRQ=1;
#define Clr_PRESET_FRQ           Key_Flag0.field.F_PRESET_FRQ=0;
#define Get_PRESET_FRQ          Key_Flag0.field.F_PRESET_FRQ
#define	Set_iPod_Video	 	 Key_Flag0.field.F_iPod_Video=1;
#define	Clr_iPod_Video	 	 Key_Flag0.field.F_iPod_Video=0;
#define	Get_iPod_Video	 	 Key_Flag0.field.F_iPod_Video
#define Set_SysSetup_Flag      Key_Flag0.field.F_NAVI_INSETUP=1;
#define Clr_SysSetup_Flag      Key_Flag0.field.F_NAVI_INSETUP=0;
#define Get_SysSetup_Flag      Key_Flag0.field.F_NAVI_INSETUP

#define Set_Volume_Flag        Key_Flag0.field.F_Volume=1;
#define Clr_Volume_Flag        Key_Flag0.field.F_Volume=0;
#define Get_Volume_Flag        Key_Flag0.field.F_Volume

#define Set_ScreenSetup_Flag    Key_Flag0.field.F_ScreenSetup=1; 
#define Clr_ScreenSetup_Flag    Key_Flag0.field.F_ScreenSetup=0; 
#define Get_ScreenSetup_Flag    Key_Flag0.field.F_ScreenSetup///main menu

#define Get_Navi_BtMenuOpen		Key_Flag0.field.F_WINCE_BTINIT

#define F_POWER_TEMP_ON		Key_Flag0.field.F_TEMP_ON

typedef struct
{
	//unsigned F_TUN_Seek         	:1;
	unsigned F_StandbyInReverse	:1;
	unsigned F_TUN_PWRINIT   	:1;
	unsigned  F_2M_TICK			:1;
	unsigned F_CCFLVideoMute   	:1;
	unsigned TFT_Blank_RGB		:1;
	unsigned F_Standby			:1;
	unsigned F_TFT_OPEN			:1;
	unsigned F_WARNING			:1;
}_KEY_FLAG1;
typedef union
{
	uchar		byte;
	_KEY_FLAG1 	field;
}KEY_FLAG1;
ext     KEY_FLAG1 Key_Flag1;

#define F_2Minute_tick			Key_Flag1.field.F_2M_TICK

#define F_RadioPwrOn_Init		Key_Flag1.field.F_TUN_PWRINIT


#define bCCFLVideoMute		Key_Flag1.field.F_CCFLVideoMute

#define  Set_TFT_Blank_RGB	Key_Flag1.field.TFT_Blank_RGB=1;
#define  Clr_TFT_Blank_RGB	Key_Flag1.field.TFT_Blank_RGB=0;
#define  Get_TFT_Blank_RGB	Key_Flag1.field.TFT_Blank_RGB

#define Set_Standby_Mode	   Key_Flag1.field.F_Standby=1; 
#define Clr_Standby_Mode	   Key_Flag1.field.F_Standby=0; 
#define Get_Standby_Mode	   Key_Flag1.field.F_Standby

#define Set_Standby_InReverse	   Key_Flag1.field.F_StandbyInReverse=1; 
#define Clr_Standby_InReverse	   Key_Flag1.field.F_StandbyInReverse=0; 
#define Get_Standby_InReverse	   Key_Flag1.field.F_StandbyInReverse

#define	Set_Open_Ctr	 	 Key_Flag1.field.F_TFT_OPEN=1;
#define	Clr_Open_Ctr	 	 Key_Flag1.field.F_TFT_OPEN=0;
#define	Get_Open_Ctr	 	 Key_Flag1.field.F_TFT_OPEN

#define	Set_Warning_Dsp 	 Key_Flag1.field.F_WARNING=1;
#define	Clr_Warning_Dsp 	 Key_Flag1.field.F_WARNING=0;
#define	Get_Warning_Dsp 	 Key_Flag1.field.F_WARNING

#define TFT_INIT_OK			Key_Flag1.field.TFT_Blank_RGB==0

#if 0
typedef struct
{
	unsigned F_MPEG_VIDEO_PLAY          	:1;
	unsigned F_MPEG_CLIPS_MEDIA    	     	:1;
	unsigned F_MPEG_IN_SOURCE_MENU   	   	:1;
	unsigned F_MPEG_IN_SETUP_MENU  			:1;
	unsigned F_MPEG_IN_EQ_MENU 				:1;
	unsigned F_MPEG_IN_FACTORY_MENU         :1;
	unsigned F_MPEG_PHROHIBIT_OPERATION    	:1;
	unsigned F_MPEG_WHEELSTY_MENU		    :1;
}_KEY_FLAG2;
typedef union
{
	uchar		byte;
	_KEY_FLAG2 	field;
}KEY_FLAG2;
ext     KEY_FLAG2 Key_Flag2;

#define F_MPEG_VIDEO_PLAY			Key_Flag2.field.F_MPEG_VIDEO_PLAY
#define F_MPEG_CLIPS_MEDIA			Key_Flag2.field.F_MPEG_CLIPS_MEDIA
#define F_INSOURCE_MENU				Key_Flag2.field.F_MPEG_IN_SOURCE_MENU	
#define F_INSETUP_MENU				Key_Flag2.field.F_MPEG_IN_SETUP_MENU	
#define F_INEQ_MENU					Key_Flag2.field.F_MPEG_IN_EQ_MENU
#define F_INFACTORY_MENU			Key_Flag2.field.F_MPEG_IN_FACTORY_MENU	
#define F_FORBIT_OPERATION			Key_Flag2.field.F_MPEG_PHROHIBIT_OPERATION	
#define F_INWHEELSTY_MENU			Key_Flag2.field.F_MPEG_WHEELSTY_MENU	
#else
typedef struct
{
	unsigned F_MPEG_MENU_STATE          	:4;
	unsigned F_MPEG_VIDEO_PLAY		   	  	:1;
	unsigned F_MPEG_CLIPS_MEDIA    	     	:1;
	unsigned F_MPEG_PHROHIBIT_OPERATION    	:1;
	unsigned F_ST_SENT						:1;

}_KEY_FLAG2;
typedef union
{
	uchar		byte;
	_KEY_FLAG2 	field;
}KEY_FLAG2;
ext     KEY_FLAG2 Key_Flag2;///get state from mpeg

#define F_MPEG_VIDEO_PLAY			Key_Flag2.field.F_MPEG_VIDEO_PLAY
#define F_MPEG_CLIPS_MEDIA			Key_Flag2.field.F_MPEG_CLIPS_MEDIA
#define F_MPEG_FORBIT_OPERATION		Key_Flag2.field.F_MPEG_PHROHIBIT_OPERATION	


#define F_MPEG_INSOURCE_MENU		Key_Flag2.field.F_MPEG_MENU_STATE ==1	
#define F_MPEG_INSETUP_MENU			Key_Flag2.field.F_MPEG_MENU_STATE ==2		
#define F_MPEG_INEQ_MENU			Key_Flag2.field.F_MPEG_MENU_STATE ==3
#define F_MPEG_INTSC_MENU			Key_Flag2.field.F_MPEG_MENU_STATE ==4
#define F_MPEG_INFACTORY_MENU		Key_Flag2.field.F_MPEG_MENU_STATE ==5	
#define F_MPEG_INWHEELSTY_MENU		Key_Flag2.field.F_MPEG_MENU_STATE ==6		

#define Get_SentST_Flag        		Key_Flag2.field.F_ST_SENT

#endif

typedef struct
{
	unsigned  F_IPOD_CNT_PRIV          	:1;
	unsigned  F_SD_CNT_PRIV   	     	:1;
	unsigned  F_USB_CNT_PRIV  	   		:1;
	unsigned  F_DISC_CNT_PRIV			:1;
	unsigned  F_MUTE_DSP				:1;
	unsigned  F_MIRROR_DSP				:1;
	unsigned  F_TV_AS					:1;
	unsigned  F_TV_MANNAL				:1;
}_KEY_FLAG3;
typedef union
{
	uchar		byte;
	_KEY_FLAG3 	field;
}KEY_FLAG3;
ext     KEY_FLAG3  Key_Flag3;

#define Ipod_Connected_Bake 	Key_Flag3.field.F_IPOD_CNT_PRIV	
#define Sd_Connected_Bake		Key_Flag3.field.F_SD_CNT_PRIV	
#define Usb_Connected_Bake		Key_Flag3.field.F_USB_CNT_PRIV	
#define Disc_Exit_Bake			Key_Flag3.field.F_DISC_CNT_PRIV	
#define Set_ScnMute_Flag		Key_Flag3.field.F_MUTE_DSP=1;
#define Clr_ScnMute_Flag		Key_Flag3.field.F_MUTE_DSP=0;
#define Get_ScnMute_Flag		Key_Flag3.field.F_MUTE_DSP

#define Get_Mirror_Dsp			Key_Flag3.field.F_MIRROR_DSP

#define Set_TV_AS				Key_Flag3.field.F_TV_AS=1;
#define Clr_TV_AS				Key_Flag3.field.F_TV_AS=0;
#define Get_TV_AS				Key_Flag3.field.F_TV_AS

#define Set_TV_MANNAL			Key_Flag3.field.F_TV_MANNAL=1;
#define Clr_TV_MANNAL			Key_Flag3.field.F_TV_MANNAL=0;
#define Get_TV_MANNAL			Key_Flag3.field.F_TV_MANNAL

typedef struct
{
	unsigned  F_SENDNAVI_DATA_LONG_INTERVAL          	:1;
	unsigned  F_MPEG_RST_OK						    	:1;
	unsigned  F_NO_SIGNAL_DSP							:1;
	unsigned  F_RDS_SIGNAL_OK							:1;
	
 	unsigned  F_BACKLIGHT_PWM							:1;
	unsigned  F_776_BURN								:1;
	unsigned  F_776_STARTR								:1;
	unsigned F_NAVI_INITOK      						:1; 

}_KEY_FLAG4;
typedef union
{
	uchar		byte;
	_KEY_FLAG4 	field;
}KEY_FLAG4;
ext     KEY_FLAG4  Key_Flag4;

#define SendNaviData_LongInterval 	Key_Flag4.field.F_SENDNAVI_DATA_LONG_INTERVAL	
#define Mpeg_Rst_StartOk		 	Key_Flag4.field.F_MPEG_RST_OK
#define Osd_NoSignal_Dsp			Key_Flag4.field.F_NO_SIGNAL_DSP
#define RDS_SIGNAL_SIGNOK			Key_Flag4.field.F_RDS_SIGNAL_OK
#define D_Backlgt_PwmOn				Key_Flag4.field.F_BACKLIGHT_PWM
#define D_776Burn_Mode				Key_Flag4.field.F_776_BURN
#define D_776Start_Set				Key_Flag4.field.F_776_STARTR

#define F_SysInit_OK				Key_Flag4.field.F_NAVI_INITOK	     

typedef struct
{
	unsigned F_AD_KEY0			:1;
	unsigned F_AD_KEY1			:1;
	unsigned F_AD_KEY2  		:1;	
	unsigned F_STDBY_ON    	    :1;	
	unsigned F_WHEELSTUDY       :1;
	unsigned F_KEY_PEND		    :1;
	unsigned F_AudioUpdate      :1;	
	unsigned F_TIME_RESET		:1;
	
}_KEY_FLAG5;
typedef union
{
	uchar	byte;
	_KEY_FLAG5 field;
}KEY_FLAG5;
ext     KEY_FLAG5 Key_Flag5;

#define F_STDBY_TEMP_ON				Key_Flag5.field.F_STDBY_ON
#define F_WHEEL_STUDY				Key_Flag5.field.F_WHEELSTUDY
#define F_AD_KEY_PEND			    Key_Flag5.field.F_KEY_PEND

#define Set_AudioUpdate			    Key_Flag5.field.F_AudioUpdate=1
#define Clr_AudioUpdate			    Key_Flag5.field.F_AudioUpdate=0
#define Get_AudioUpdate			    Key_Flag5.field.F_AudioUpdate

#define Set_TIME_RESET			    Key_Flag5.field.F_TIME_RESET=1
#define Clr_TIME_RESET			    Key_Flag5.field.F_TIME_RESET=0
#define Get_TIME_RESET			    Key_Flag5.field.F_TIME_RESET

typedef struct
{
	unsigned line1_ahead		: 1;
	unsigned line2_ahead		: 1;
	unsigned line1_change		: 1;
	unsigned line2_change		: 1;
	unsigned line1_level		: 1;
	unsigned line2_level		: 1;
	unsigned line1_active		: 1;
	unsigned line2_active		: 1;
}ENCODER;

#define WHEELKEY_CH1        1
#define WHEELKEY_CH2        2
#define NUM_AD1  	  		14
#define NUM_AD2 	  		8
#define NUM_AD3 	  		8
#define T6S_100         	60
#define T5S_100         	50
#define T3S_100         	30
#define T2S_100         	20
#define T1S_100         	10
#define T500MS_100       	5


#define T1S_12		    83
#define T2S_12		    166
#define T3S_12		    250
#define T5S_12		    416
#define T6S_12		    555

#define WHEELSTUDY_START    0xFA
#define WHEELSTUDY_STOP     0xFD
#define WHEELSTUDY_WORK     0xF5

#if D_WHEELKEY_STUDY
typedef enum
{
	WSTY_INIT,
	WSTY_RKEY1,
	WSTY_RKEY2,
	WSTY_RKEY3,
	WSTY_RKEY4,
	WSTY_RKEY5,
	WSTY_RKEY6
}WHEELSTY_STATE;
ext WHEELSTY_STATE WheelStyState;
ext uchar Wheelkey_Index;
ext uchar Wheelkey_Index_bk;
#ifndef D_STM8_INNEREEPROM
ext uchar WheelKey_Tab[2][10][3];
#endif
ext uchar WheelCtl_Study_Ok ;
ext uchar Wheel_Btn_AD[8];
ext uchar WhlKey_Pend_AD[2];
#endif

extern void Panel_Key_Scan(void);
void WheelKey_Scan_AD(uchar ADC, uchar ch,uchar num);
extern void Key_Scan_AD(uchar ADC,uchar ch,uchar num);
///extern void Encoder_Scan(void);
///extern void Power_Key_Scan(void);
#if  ENCODER_NUMBER>0
ext uchar Encoder_Scan_Timer[2];
extern void Panel_VolEncoder_Scan(void);
extern void Panel_TuneEncoder_Scan(void);
#ifdef _DEBUG_SCAN_ENCODER
void TuneEncoder_Scan(void);
#endif
#endif

#ifdef D_STM8_INNEREEPROM
void WheelKeyValueReset(void);
#endif
void WheelKeyValueInitial(void);

#if 0/// ENCODER_NUMBER>1
extern void Encorder1_Scan(void);
#endif

#endif
